package javabase.schoolwork.day7_13.d13.d13;

import org.junit.Test;

/**
 * @author Tse
 * JDK新特性：Lambda表达式
 */
public class JunitTest2 {
	public static void main(String[] args) {
		fun(() -> System.out.println("Hello World!"));
	}

	private static void fun(IPrintInter p) {
		p.print();
	}
	
	//使用Lambda表达式
	@Test
	public void fun1() {
		fun(()->System.out.println("Hello World!"));
	}
	
	//引用静态方法示例
	@Test 
	public void fun2() {
		IFunction<Integer,String> fun=String::valueOf;
		String str=fun.apply(10030);
		System.out.println(str.replaceAll("0", "X"));
	}
	
	//引用某个对象的普通方法示例
	@Test
	public void fun3() {
		IFunction2<String> fun="hello"::toUpperCase;
		String str=fun.upper();
		System.out.println(str);
	}
	//引用特定类型的方法示例
	@Test
	public void fun4() {
		IFunction3<String> fun=String ::compareTo;
		System.out.println(fun.compare("A", "C"));
	}
	
	//引用构造方法示例
	@Test
	public void fun5() {
		IFunction4<Book> fun=Book::new;
		Book book=fun.create("Java编程思想", 89.5);
		System.out.println(book);
	}
}

interface IPrintInter{
	public void print();
}

interface IFunction<T,R>{
	public R apply(T t);
}

interface IFunction2<R>{
	public R upper();
}
interface IFunction3<T>{
	public int compare(T t1, T t2);
}
interface IFunction4<R>{
	public R create(String t, double p);
}

class Book{
	private String title;
	private double price;
	public Book(String title,double price) {
		super();
		this.title = title;
		this.price=price;
	}
	@Override
	public String toString() {
		return "Book [title=" + title + ", price=" + price + "]";
	}
	
	
}